//
//  CWSportTrackingLine.m
//  大神专制黑马行
//
//  Created by chenWei on 2017/5/11.
//  Copyright © 2017年 陈伟. All rights reserved.
//

#import "CWSportTrackingLine.h"

@implementation CWSportTrackingLine

- (id)initWithStartLocation:(CLLocation *)startLocation endLocation:(CLLocation *)endLocation
{
    if (self = [super init]) {
        self.startLocation = startLocation;
        self.endLocation = endLocation;
    }
    
    return self;
}

- (CWSportPolyline *)polyline
{
    //构造折线数据对象
    CLLocationCoordinate2D commonPolylineCoordinate[2];
    
    commonPolylineCoordinate[0].latitude = self.startLocation.coordinate.latitude;
    commonPolylineCoordinate[0].longitude = self.startLocation.coordinate.longitude;
    
    commonPolylineCoordinate[1].latitude = self.endLocation.coordinate.latitude;
    commonPolylineCoordinate[1].longitude = self.endLocation.coordinate.longitude;
    
    //线条颜色
    //比例因子
    int factor= 8;
    UIColor *color = [UIColor colorWithRed:(self.speed * factor)/255.f green:1 blue:0 alpha:1];
    
    //构造折线对象
    CWSportPolyline *polyline = [[CWSportPolyline alloc] polylineWithCoordinates:commonPolylineCoordinate count:2 color:color];
    
    return polyline;
    
}

//速度的 getter 方法
- (float)speed
{
    //一个线条的平均速度=（起点瞬间速度+终点瞬间速度）/2;
    //location默认的速度是m/s  m/s转化为km/h 应该乘以3.6
    return (self.startLocation.speed+self.endLocation.speed)/2 * 3.6;
    
}


//单次轨迹运行时间
- (float)time
{
    return [self.endLocation.timestamp timeIntervalSinceDate:self.startLocation.timestamp];
    
}

//单次轨迹线条距离
- (float)distance
{
    //location的单位是m  转为km  乘以0.001
    return [self.startLocation distanceFromLocation:self.endLocation] * 0.001;
    
}


@end
